//
//  LFBLeftTableView.m
//  LFBLoveFreshBee
//
//  Created by 张睿 on 16/8/20.
//  Copyright © 2016年 丁鼎. All rights reserved.
//

#import "LFBLeftTableView.h"
#import "LFBRightTableView.h"

@interface LFBLeftTableView ()<UITableViewDataSource,UITableViewDelegate>

@property (nonatomic, strong)UITableView * leftTableView;
//@property (nonatomic, strong)LFBRightTableView * rightVC;

@end

@implementation LFBLeftTableView

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setupUI];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willDisplayHeaderView:) name:@"willDisplay" object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didEndDisplayingHeaderView:) name:@"didEndDisplaying" object:nil];
}

- (void)setupUI{
    
    self.leftTableView = [[UITableView alloc] initWithFrame:self.view.bounds];
    
    self.leftTableView.delegate = self;
    self.leftTableView.dataSource = self;
    [self.leftTableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"Left"];
    
    [self.view addSubview:self.leftTableView];
}

#pragma mark - UITableViewDataSource -

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 30;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"Left" forIndexPath:indexPath];
    cell.backgroundColor = [UIColor lightGrayColor];
    cell.textLabel.text = [NSString stringWithFormat:@"第%ld类",(long)indexPath.row];
    
    return cell;
}

#pragma mark - UITableViewDelegate -
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    NSString * row = [NSString stringWithFormat:@"%ld",indexPath.row];
    
    NSDictionary * dict = @{
                            @"row":row
                            };
    
    [[NSNotificationCenter defaultCenter] postNotificationName:@"LeftNotificationRight" object:nil userInfo:dict];
    
}

#pragma mark - ProductsDelegate
- (void)willDisplayHeaderView:(NSNotification *)dict{
    NSString * sectionStr = dict.userInfo[@"number"];
    int section = [sectionStr intValue];
    
    [self.leftTableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:section inSection:0] animated:YES scrollPosition:UITableViewScrollPositionMiddle];
}

- (void)didEndDisplayingHeaderView:(NSNotification *)dict{
    NSString * sectionStr = dict.userInfo[@"number"];
    int section = [sectionStr intValue];
    
    [self.leftTableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:section + 1 inSection:0] animated:YES scrollPosition:UITableViewScrollPositionMiddle];
}


//#pragma mark - 懒加载 -
//- (LFBRightTableView *)rightVC{
//    if (_rightVC == nil) {
//        _rightVC = [[LFBRightTableView alloc] init];
//
//    }
//
//    return _rightVC;
//}
@end
